package com.wwk.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wwk.dao.MemberDao;
import com.wwk.entity.PageResult;
import com.wwk.entity.QueryPageBean;
import com.wwk.pojo.Member;
import com.wwk.service.MemberService;
import com.wwk.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Classname MemberServiceImpl
 * @Description TODO
 * @Date 2020/11/5 10:04
 * @Created by com.wwk
 * @Author com.wwk
 */
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    @Override
    public PageResult findPage(QueryPageBean pageBean) {

        PageHelper.startPage(pageBean.getCurrentPage(),pageBean.getPageSize());
        Page<Member> members=memberDao.findMemByCondition(pageBean.getQueryString());

        return new PageResult(members.getTotal(),members.getResult());
    }

    @Override
    public Member findByTelephone(String phone) {
        return memberDao.findByTelephone(phone);
    }

    @Override
    public Member findMemById(Integer memId) {
        return memberDao.findMemById(memId);
    }

    @Override
    public void edit(Member member) {
        memberDao.edit(member);
    }

    @Override
    public void add(Member member) {
        if(member.getPassword()!=null){
            member.setPassword(MD5Utils.md5(member.getPassword()));
        }
        memberDao.add(member);
    }
}
